package algotithm.leetcode.twopoint.test11;

/**
 * @author zhouyanxiang
 * @Date 2021-04-2021/4/19-22:25
 * @Title 11. 盛最多水的容器
 */
public class Solution {

    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] height = {1,8,6,2,5,4,8,3,7};
        int i = solution.maxArea(height);
        System.out.println(i);
    }

    public int maxArea(int[] height) {
        int l = 0, r = height.length - 1;
        int ans = 0;
        while (l < r) {
            int area = Math.min(height[l],height[r]) * (r - l);
            ans = Math.max(ans,area);
            if (height[l] < height[r]) {
                l++;
            } else {
                r--;
            }
        }
        return ans;
    }

}
